package com.neuedu.mblog.controller;

import com.neuedu.mblog.common.CommonResult;
import com.neuedu.mblog.dao.ChannelDao;
import com.neuedu.mblog.entiry.Channel;
import com.neuedu.mblog.service.ChannelService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * 项目：vue-ifs
 * 创建时间：  2022-03-11   9:43
 * 作者 :jshand
 * 描述 : ${dc}
 */
@WebServlet(name = "ChannelControlelr",urlPatterns = "/channel")
public class ChannelControlelr extends BaseController {

    ChannelService channelService = new ChannelService();

    /**
     * 查询列表
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     * http://localhost:8080/vue-ifs/channel?_type=list
     */
    @Override
    public void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {


        List<Channel> list = channelService.list();
        super.jsonResult(response, CommonResult.success(list));

    }



    public void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        boolean success = channelService.save(request);
        super.jsonResult(response, CommonResult.success(success));

    }

    public void queryById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        Channel channel = channelService.queryById(request);
        super.jsonResult(response, CommonResult.success(channel));

    }
    @Override
    public void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        boolean success = channelService.update(request);
        super.jsonResult(response, CommonResult.success(success));
    }

    @Override
    public void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        boolean success = channelService.delete(request);
        super.jsonResult(response, CommonResult.success(success));
    }
}
